<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +---------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace cmf\controller;
use think\Request;
use think\Db;

class UserBaseController extends HomeBaseController
{
    protected $user = [];

    public function _initialize()
    {
        parent::_initialize();
        header('Access-Control-Allow-Origin:*');
        $this->validateToken();
    }
    protected function validateToken () {
        $post = Request::instance()->param();
        $token = isset($post["token"]) ? $post["token"] : '';
        if(empty($token)){
            header("HTTP/1.1 401 Unauthorized");
            exit;
        }

        $user = Db::name('user_token')->where('token',$token)->find();        
        if(empty($user)){
            header("HTTP/1.1 401 Unauthorized");
            exit;
        }
        $this->user = $user;
    }
}